package com.afd.ozblip.activity;

import com.afd.ozblip.image.LoadImage;
import com.afd.ozblip.util.StringUtil;
import com.afd.ozblip.view.ViewArea;

import android.content.Intent;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

public class ImageShowActivity extends BaseActivity {

	/****************** 视图变量 **************************/
	private LinearLayout imgShowLayout;
	private TextView loadTv;
	private ViewArea viewArea;

	/****************** 数据变量 **************************/
	private LoadImage loadImage;
	private String imageUrl;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.image_show);
		// 启动返回功能
		toBack();
		// 寻找视图
		findViews();
		// 设置监听
		setListeners();
		// 获取参数
		getBundle();
		// 设置视图
		setView();
	}

	/**
	 * 寻找视图
	 */
	public void findViews() {
		this.imgShowLayout = (LinearLayout) this.findViewById(R.id.ll_imgshow);
		this.loadTv = (TextView) this.findViewById(R.id.tip_text_noData);
		this.viewArea = new ViewArea(ImageShowActivity.this, 0);
		LinearLayout.LayoutParams parm = new LinearLayout.LayoutParams(
				LinearLayout.LayoutParams.MATCH_PARENT,
				LinearLayout.LayoutParams.MATCH_PARENT);
		parm.gravity = Gravity.RIGHT;
		this.imgShowLayout.addView(viewArea, parm);
	}

	/**
	 * 设置监听
	 */
	public void setListeners() {
		View.OnClickListener moreClick = new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				switch (v.getId()) {
				case R.id.ll_more_layout_setting:
					Intent settingIntent = new Intent(ImageShowActivity.this,
							SettingActivity.class);
					startActivity(settingIntent);
					break;

				default:
					break;
				}
			}
		};
	}

	/**
	 * 获取传递的参数
	 */
	private void getBundle() {
		Intent intent = getIntent();
		this.imageUrl = intent.getStringExtra("imageUrl");
	}

	private void setView() {
		// 加载图片
		if (!StringUtil.isNullOrEmpty(imageUrl)) {
			loadTv.setVisibility(0);
			loadImage = new LoadImage(this);
			loadImage.addTask(imageUrl, viewArea.touchView, loadTv);
		}
	}
}